package com.jsu.springboot_medicine.controller;

import com.jsu.springboot_medicine.common.Result;
import com.jsu.springboot_medicine.common.StatusCode;
import com.jsu.springboot_medicine.entity.Check;
import com.jsu.springboot_medicine.service.CheckService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author js
 * @name CheckController
 * @Date 2023/10/1 16:14
 */
@RestController
@RequestMapping("/check")
@CrossOrigin
public class CheckController {
    @Resource
    private CheckService CheckService;

    @GetMapping
    public Result<List<Check>> selectAll() {
        List<Check> checks = CheckService.selectAll();
        return new Result<List<Check>>(true, StatusCode.OK, "查询成功", checks);
    }

    @GetMapping("/{id}")
    public Result<Check> selectById(@PathVariable("id") int id){
        Check check = CheckService.selectById(id);
        return new Result<Check>(true,StatusCode.OK,"查询成功",check);
    }

    @PostMapping("/update")
    public Result update(@RequestBody Check check) {
        CheckService.update(check);
        return new Result(true, StatusCode.OK, "修改成功",null);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") int id) {
        CheckService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功",null);
    }

    @PostMapping("/inset")
    public Result insert(@RequestBody Check Check) {
        CheckService.insert(Check);
        return new Result(true, StatusCode.OK, "插入成功",null);
    }
}
